﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DomainModel;
using Utils;
using WebUI.Utils;

namespace WebUI.Models
{
    public class JobListViewModel : BaseViewModel
    {
        private int _numPerPage = 20;

        public JobListViewModel()
            : base()
        { }

        public JobListViewModel(string t, int page)
            : base(new { T = t, Page = page })
        { }

        public string AvatarUrl { get; set; }
        public Co Co { get; set; }

        public List<Job> JobList { get; set; }

        public string FilterType { get; set; }

        public int Page { get; set; }
        public int PreviousPage { get; set; }
        public int NextPage { get; set; }

        protected override void SetVarsWhichDependOnDynamicParams(dynamic dynParams)
        {
            FilterType = dynParams.T;
            Page = dynParams.Page;
            //get co
            Co = DataUtils.GetOne<Co>(ConstUtils.SP_GetCo, new { Identity.LoginID, CoID = Identity.AccountID }); 
            //get job list
            int status = ViewModelUtils.GetJobStatusByFilterType(FilterType);
            JobList = DataUtils.GetList<Job>(ConstUtils.SP_GetJobListByCoID, new { Co.CoID, status, Page, NumPerPage = _numPerPage });

            //get next page
            int totalCount = JobList != null && JobList.Count > 0 ? JobList[0].TotalCount : 0;
            PreviousPage = CommonUtilities.GetPreviousPage(Page);
            NextPage = CommonUtilities.GetNextPage(totalCount, Page, _numPerPage);
            //get avatar 
            AvatarUrl = ImageUtils.GetAvatarRelativeUrl(AvatarType.CoAvatar, Co.CoID, AvatarSizeEnum.Avatar_80x80, Co.AvatarFileExtension);
        }

        
    }
}